#pragma once

/*
 * A collection of cryptographic functions
 * Dependencies: bzbutil, system API (WinAPI / POSIX),
 * 				libgcrypt, libgpg-error if BZBCRYPTO_UNSTABLE is defined.
 */

#include <vector>
#include <string>


namespace bzbcrypto {


/*
 * Returns a cryptographically secure random value
 * Uses libgcrypt if supported, otherwise uses a fallback system function
 * (CryptGenRandom on Windows, getrandom on Linux)
 * Throws a std::system_error on error.
 */

int get_secure_random();


#ifdef BZBCRYPTO_UNSTABLE


/*
 * Initializes libgcrypt library
 * NOTE: You don't have to explicitly call this function, as it will be
 * automatically called when the first cryptographic function will be called,
 * but for better performance it is advised to do so.
 *
 * Throws a std::runtime_error on error
 */

void init_gcrypt();


/*
 * Digests the given string using the SHA256 algorithm
 * Throws a std::runtime_error if the argument is empty
 */

std::string digest_SHA256(std::string plaintext);


/*
 * Digests the given data using the SHA256 algorithm
 * Throws a std::runtime_error if the argument is empty
 */

std::string digest_SHA256(std::vector<unsigned char> data);


/*
 * Digests the given string using the SHA512 algorithm
 * Throws a std::runtime_error if the argument is empty
 */

std::string digest_SHA512(std::string plaintext);


/*
 * Digests the given data using the SHA512 algorithm
 * Throws a std::runtime_error if the argument is empty
 */

std::string digest_SHA512(std::vector<unsigned char> data);


#endif


}

